using System;
using System.Globalization;
using System.Linq;
using Azure.Domain.Models;
using Azure.Domain.Services;
using Azure.Infrastructure;
using Azure.Membership;
using Azure.Web.Stubs;

namespace Azure.Web.Configuration
{
    public class Stub : CommonRegistry
    {
        public Stub()
        {
            var postRepository = new StubRepository<Post>();
            var userRepository = new StubRepository<User>();
            var configRepository = new StubRepository<SiteConfiguration>();
            var created = DateTime.Parse("January 1, 2010", new CultureInfo("en-US"));
            var rowKey = (DateTime.MaxValue.Ticks - created.Ticks).ToString();
            postRepository.Insert(new Post("79899898", rowKey) { Title = Properties.Resources.Fill_Title, Slug = "lorem-ipsum", Body = Properties.Resources.Fill_Body, Created = created, Timestamp = DateTime.UtcNow });
            userRepository.Insert(new User { Email = "admin@weiker.org", PartitionKey = "admin", Password = "nsYa7iSQA+lYr5iS5iyPzazmtMY=", RowKey = new Guid("9d260e9c-9123-40be-8fe7-c64c600395dd").ToString(), UserName = "admin" });
            configRepository.Insert(new SiteConfiguration { Email="admin@weiker.org", Title = "Test Site", Owner = "Aaron Weiker" });
            
            For<IBlogConfiguration>()
                .Use<BlogConfiguration>();
            For(typeof (IRepository<>))
                .Use(typeof (StubRepository<>));
            For(typeof(IQueue<>))
                .Use(typeof(StubQueue<>));
            For<IMembershipRepository>()
                .Use<StubMembershipRepository>();
            Scan(x =>
                     {
                         x.Assembly("Infrastructure");
                         x.Assembly("Membership");
                         x.Assembly("Domain");
                         x.Assembly("Webby");
                         x.ExcludeNamespace("Azure.Infrastructure.Azure");
                         x.ExcludeNamespace("Azure.Domain.Services.Azure");
                         x.WithDefaultConventions();
                     });
        }
    }
}